﻿namespace FallingRocks
{
    using System;

    public class KeyboardInterface : IUserInterface
    {        
        public KeyboardInterface()
        {
            ControlPanel.ReloadSettings();
        }

        public event EventHandler OnLeftPressed;
         
        public event EventHandler OnRightPressed;

        public event EventHandler OnActionPressed;

        public event EventHandler OnPausePressed;

        public event EventHandler OnMenuPressed;

        public event EventHandler OnMenuUpPressed;

        public event EventHandler OnMenuDownPressed;

        public event EventHandler OnMenuSelectPressed;

        public event EventHandler OnQuitMenuPressed;

        public event EventHandler OnQuitPausePressed;

        public void ProcessInput()
        {
            if (Console.KeyAvailable)
            {
                ConsoleKeyInfo keyInfo = Console.ReadKey();    // ConsoleKey keyInfo = Console.ReadKey().Key;

                // TODO          while in Game,Playing
                if (true)   
                {
                    if (keyInfo.Key.Equals(Key.DefMovingLeft) || keyInfo.Key.Equals(Key.MovingLeft))
                    {
                        if (this.OnLeftPressed != null)
                        {
                            this.OnLeftPressed(this, new EventArgs());
                        }
                    }

                    if (keyInfo.Key.Equals(Key.DefMovingRight) || keyInfo.Key.Equals(Key.MovingRight))
                    {
                        if (this.OnRightPressed != null)
                        {
                            this.OnRightPressed(this, new EventArgs());
                        }
                    }

                    if (keyInfo.Key.Equals(Key.DefActivate) || keyInfo.Key.Equals(Key.Activate))
                    {
                        if (this.OnActionPressed != null)
                        {
                            this.OnActionPressed(this, new EventArgs());
                        }
                    }

                    if (keyInfo.Key.Equals(Key.DefPause) || keyInfo.Key.Equals(Key.Pause))
                    {
                        if (this.OnPausePressed != null)
                        {
                            this.OnPausePressed(this, new EventArgs());
                        }
                    }

                    if (keyInfo.Key.Equals(Key.DefMenu))
                    {
                        if (this.OnMenuPressed != null)
                        {
                            this.OnMenuPressed(this, new EventArgs());
                        }
                    }
                }

                // TODO          while in MENU
                if (true)   
                {
                    if (keyInfo.Key.Equals(Key.DefMenuUp))
                    {
                        if (this.OnMenuUpPressed != null)
                        {
                            this.OnMenuUpPressed(this, new EventArgs());
                        }
                    }

                    if (keyInfo.Key.Equals(Key.DefMenuDown))
                    {
                        if (this.OnMenuDownPressed != null)
                        {
                            this.OnMenuDownPressed(this, new EventArgs());
                        }
                    }

                    if (keyInfo.Key.Equals(Key.DefMenuSelect))
                    {
                        if (this.OnMenuSelectPressed != null)
                        {
                            this.OnMenuSelectPressed(this, new EventArgs());
                        }
                    }

                    if (keyInfo.Key.Equals(Key.DefMenu))
                    {
                        if (this.OnQuitMenuPressed != null)
                        {
                            this.OnQuitMenuPressed(this, new EventArgs());
                        }
                    }
                }

                // TODO          while in MENU
                if (true)   
                {
                    if (keyInfo.Key.Equals(Key.DefMenu))
                    {
                        if (this.OnQuitPausePressed != null)
                        {
                            this.OnQuitPausePressed(this, new EventArgs());
                        }
                    }
                }

                if (keyInfo.Key.Equals(Key.DefPause) || keyInfo.Key.Equals(Key.Pause))
                {
                    if (this.OnQuitPausePressed != null)
                    {
                        this.OnQuitPausePressed(this, new EventArgs());
                    }
                }
            }
        }
    }
}